//
//  AreaHeadReusableView.m
//  Lovelife
//
//  Created by dllo on 15/4/27.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "AreaHeadReusableView.h"
#import "NightManager.h"
@implementation AreaHeadReusableView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 创建滚动视图
        // 网络加载 --- 创建带标题的图片轮播器
        self.cycleScrollView = [[SDCycleScrollView alloc]init];
        self.cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
        self.cycleScrollView.delegate = self;
        self.cycleScrollView.dotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
        self.cycleScrollView.autoScrollTimeInterval = 4.0;
        
        [self addSubview:self.cycleScrollView];
        [_cycleScrollView release];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            self.cycleScrollView.imageURLsGroup = self.photoArr;

            // 创建按钮实用信息按钮
            self.informationButton = [self createButton:@"QYCountryInfoButton@2x.png"  tag:101 title:@"实用信息" ifHave:self.ifHaveInformation];
            self.recommendTripButton = [self createButton:@"QYCountryPlanButton@2x.png" tag:102 title:@"推荐行程" ifHave:self.ifHaveGuide];
        });
        
        // 创建标签显示国家名称
        self.nameLable = [[BaseLabel alloc]init];
        self.nameLable.numberOfLines = 0;
        self.nameLable.backgroundColor = [UIColor clearColor];
        self.nameLable.textColor = [UIColor whiteColor];
        [self addSubview:self.nameLable];
        [_nameLable release];
        
        // 创建标题标签
        self.titleLabel = [[BaseLabel alloc]init];
        self.titleLabel.numberOfLines = 0;
        self.titleLabel.backgroundColor = [UIColor clearColor];
        [self addSubview:self.titleLabel];
        [_titleLabel release];
        
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.cycleScrollView.frame = CGRectMake(0, 0, self.frame.size.width, 180);
    self.nameLable.frame =  CGRectMake(20, 130, self.frame.size.width - 20, 50);
    self.informationButton.frame = CGRectMake(50, 200, 100, 40);
    self.recommendTripButton.frame = CGRectMake(170, 200, 100, 40);
    self.titleLabel.frame = CGRectMake(20, 260, 200, 20);
}
- (BaseButton *)createButton:(NSString *)imageName
                       tag:(NSInteger)tag
                     title:(NSString *)title
                      ifHave:(BOOL)ifHave
{
    BaseButton *button = [BaseButton buttonWithType:UIButtonTypeCustom];
    button.tag = tag;
    button.layer.borderWidth = 1;
    button.layer.cornerRadius = 5;
    button.enabled = !ifHave;
    if (button.enabled) {
        button.backgroundColor = [UIColor greenColor];
    }else{
        button.backgroundColor = [UIColor redColor];

    }
    [button setTitle:title forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:button];
    return button;
}
- (void)buttonAction:(BaseButton *)button
{
    [self.delegate push:button.tag];
}
- (void)setNightDayModel
{
    [NightManager setBackgroundColorWithView:self];
    [NightManager setLabelColorWithLabel:self.titleLabel];
}
- (void)setLightDayModel
{
    [NightManager setBackgroundColorWithView:self];
    [NightManager setLabelColorWithLabel:self.titleLabel];
}
- (void)dealloc
{
    [_photoArr release];
    [_cycleScrollView release];
    [_nameLable release];
    [_informationButton release];
    [_recommendTripButton release];
    [_titleLabel release];
    [super dealloc];
}

@end
